home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C ++ / Applications / FlyThrough 1.1.2 / src / Source / CFlyThroughApp.cp next >
Encoding:
Text File  |  1997-05-14  |  5.2 KB  |  224 lines  |  [TEXT/CWIE]

  1. // ===========================================================================
  2. //    CFlyThroughApp.cp
  3. // ===========================================================================
  4. //
  5.  
  6. #include "CFlyThroughApp.h"
  7.  
  8. #include "StQD3DInitializer.h"
  9. #include "CQD3DErrorWindow.h"        // for reporting QD3D errors
  10.  
  11. #include "CQD3DPane.h"
  12. #include "CVehicleViewPane.h"
  13. #include "CFlyThroughDoc.h"
  14.  
  15. #include "CAGASlider.h"
  16. #include "CBevelAttachment.h"
  17.  
  18. #include <LGrowZone.h>
  19. #include <LWindow.h>
  20. #include <PP_Messages.h>
  21. #include <PP_Resources.h>
  22. #include <PPobClasses.h>
  23. #include <UDrawingState.h>
  24. #include <UMemoryMgr.h>
  25. #include <URegistrar.h>
  26. #include <LEditField.h>
  27.  
  28. const ResIDT    ALRT_QD3DNotInstalled = 1000;
  29.  
  30. // ===========================================================================
  31. //        • Main Program
  32. // ===========================================================================
  33.  
  34. void main(void)
  35. {
  36.                                     // Set Debugging options
  37.     SetDebugThrow_(debugAction_Alert);
  38. #if 1
  39.     SetDebugSignal_(debugAction_Alert);
  40. #else
  41.     SetDebugSignal_(debugAction_SourceDebugger);
  42. #endif
  43.  
  44.     InitializeHeap(3);                // Initialize Memory Manager
  45.                                     // Parameter is number of Master Pointer
  46.                                     //   blocks to allocate
  47.     
  48.                                     // Initialize standard Toolbox managers
  49.     UQDGlobals::InitializeToolbox(&qd);
  50.     
  51.     new LGrowZone(20000);            // Install a GrowZone function to catch
  52.                                     //    low memory situations.
  53.  
  54.     StQD3DInitializer q3;            // Initalize QuickDraw 3D
  55.     if ( q3.GetStatus() == kQ3Success ) {
  56.     
  57.         CFlyThroughApp    theApp;
  58.         
  59.         // Make the QD3D Error Message window.
  60.     //    CQD3DErrorWindow::Install( &theApp );
  61.         
  62.         theApp.Run();
  63.         
  64.     } else {
  65.     
  66.     //    SignalPStr_("\pThis application requires QuickDraw 3D.");
  67.         ::StopAlert( ALRT_QD3DNotInstalled, UModalFilter::GetFilter() );
  68.         
  69.     }
  70. }
  71.  
  72.  
  73. // ---------------------------------------------------------------------------
  74. //        • CFlyThroughApp             // replace this with your App type
  75. // ---------------------------------------------------------------------------
  76. //    Constructor
  77.  
  78. CFlyThroughApp::CFlyThroughApp()
  79. {
  80.     // Register functions to create core PowerPlant classes
  81.     
  82.     RegisterAllPPClasses();
  83.     
  84.     CQD3DPane::Register();
  85.     CVehicleViewPane::Register();
  86.     CAGASlider::Register();
  87.     CBevelAttachment::Register();
  88. }
  89.  
  90.  
  91. // ---------------------------------------------------------------------------
  92. //        • ~CFlyThroughApp            // replace this with your App type
  93. // ---------------------------------------------------------------------------
  94. //    Destructor
  95. //
  96.  
  97. CFlyThroughApp::~CFlyThroughApp()
  98. {
  99. }
  100.  
  101. // ---------------------------------------------------------------------------
  102. //        • StartUp
  103. // ---------------------------------------------------------------------------
  104. //    This function lets you do something when the application starts up
  105. //    without a document. For example, you could issue your own new command.
  106.  
  107. void
  108. CFlyThroughApp::StartUp()
  109. {
  110. #ifdef HAS_NEW_SCENE_MENU
  111.     ObeyCommand(cmd_8Cubes, nil);
  112. #else
  113.     ObeyCommand(cmd_Open, nil);
  114. #endif // HAS_NEW_SCENE_MENU
  115. }
  116.  
  117. // ---------------------------------------------------------------------------
  118. //        • ObeyCommand
  119. // ---------------------------------------------------------------------------
  120. //    Respond to commands
  121.  
  122. Boolean
  123. CFlyThroughApp::ObeyCommand(
  124.     CommandT    inCommand,
  125.     void        *ioParam)
  126. {
  127.     Boolean        cmdHandled = true;
  128.  
  129.     switch (inCommand) {
  130.     
  131.         // Deal with command messages (defined in PP_Messages.h).
  132.         // Any that you don't handle will be passed to LApplication
  133.              
  134. #ifdef HAS_NEW_SCENE_MENU
  135.     case cmd_8Cubes:
  136.     case cmd_27Cubes:
  137.     case cmd_64Cubes:
  138.     case cmd_Scatter20Box:
  139.     case cmd_Scatter40Box:
  140.     case cmd_TriGridBox10:
  141.     case cmd_TriGridBox30:
  142.         
  143.         new CFlyThroughDoc(this,inCommand);
  144.         break;
  145. #endif // HAS_NEW_SCENE_MENU
  146.         
  147.     case cmd_Open:
  148.         ChooseDocument();
  149.         break;
  150.  
  151.     default:
  152.         cmdHandled = LApplication::ObeyCommand(inCommand, ioParam);
  153.         break;
  154.     }
  155.     
  156.     return cmdHandled;
  157. }
  158.  
  159. // ---------------------------------------------------------------------------
  160. //        • FindCommandStatus
  161. // ---------------------------------------------------------------------------
  162. //    This function enables menu commands.
  163. //
  164.  
  165. void
  166. CFlyThroughApp::FindCommandStatus(
  167.     CommandT    inCommand,
  168.     Boolean        &outEnabled,
  169.     Boolean        &outUsesMark,
  170.     Char16        &outMark,
  171.     Str255        outName)
  172. {
  173.  
  174.     switch (inCommand) {
  175.     
  176.         // Return menu item status according to command messages.
  177.         // Any that you don't handle will be passed to LApplication
  178.  
  179.     case cmd_Open:
  180.         outEnabled = true;
  181.         break;
  182.  
  183. #ifdef HAS_NEW_SCENE_MENU
  184.     case cmd_New:
  185.         outEnabled = true;            // enable the New sub-menu
  186.         break;
  187.  
  188.     case cmd_8Cubes:
  189.     case cmd_27Cubes:
  190.     case cmd_64Cubes:
  191.     case cmd_Scatter20Box:
  192.     case cmd_Scatter40Box:
  193.     case cmd_TriGridBox10:
  194.     case cmd_TriGridBox30:
  195.         outEnabled = true;
  196.         break;
  197. #endif // HAS_NEW_SCENE_MENU
  198.         
  199.         default:
  200.             LApplication::FindCommandStatus(inCommand, outEnabled,
  201.                                                 outUsesMark, outMark, outName);
  202.             break;
  203.     }
  204. }
  205.  
  206. void    CFlyThroughApp::OpenDocument( FSSpec *inMacFSSpec)
  207. {
  208.     new CFlyThroughDoc(this, inMacFSSpec);
  209. }
  210.  
  211. void    CFlyThroughApp::ChooseDocument()
  212. {
  213.     SFTypeList    kTypeList = { '3DMF' };
  214.     const Int16 kTypeCount = 1;
  215.     
  216.     StandardFileReply    theReply;
  217.     ::UDesktop::Deactivate();
  218.     ::StandardGetFile( nil, kTypeCount, kTypeList, &theReply );
  219.     ::UDesktop::Activate();
  220.     
  221.     if ( theReply.sfGood ) SendAEOpenDoc( theReply.sfFile );
  222. }
  223.  
  224.